package com.coolbi.onsupai.core.util;

import java.util.Date;

import com.coolbi.common.util.CommonUtil;
import com.coolbi.common.util.DateUtil;
import com.coolbi.onsupai.core.entity.Order;

/**
 * @Description 订单工具类
 * @author for2cold
 * @codeDate 2012-8-16 下午06:02:40
 *
 */
public class OrderUtils {
	
	private static Integer serialNo = 0;

	/**
	 * 货款合计
	 * @param prices 商品单价列表
	 * @param order 订单对象
	 * @return double payMoney 支付金额
	 */
	public static double payAmount(String prices, Order order) {
		double amount = 0d;
		double sum = 0d;
		double[] priceArray = CommonUtil.parseToDouble(prices, ", ");
		double[] quantityArray = CommonUtil.parseToDouble(order.getQuantitys(), ", ");
		double[] discountArray = CommonUtil.parseToDouble(order.getDiscounts(), ", ");
		int length = priceArray.length;
		for (int i = 0; i < length; i ++) {
			sum = priceArray[i] * discountArray[i] * quantityArray[i];
			amount += sum;
		}
		return amount;
	}
	
	public static String generateOrderNo() {
		serialNo ++;
		String time = DateUtil.formart(new Date(), "yyyyMMdd") + serialNo;
		return time;
	}
}
